# Maintainer: David Runge <dvzrv@archlinux.org>

pkgbase=rtosc
pkgname=(
  rtosc
  rtosc-docs
)
pkgver=0.3.1
pkgrel=2
pkgdesc="Realtime safe OSC Messaging"
arch=(loong64 x86_64)
url="https://github.com/fundamental/rtosc"
license=(MIT)
makedepends=(
  asciidoctor
  cmake
  doxygen
)
source=($url/archive/v$pkgver/$pkgbase-v$pkgver.tar.gz)
sha512sums=('55bb8282bdefaee2c8c2187f523bba889d66d6ba051bc6ff2c443ef171e0ae5f12048c95014cf127076234d4d59b4052ac0dfcae4ade7d7d4a8cf14057cf2a0a')
b2sums=('01744e56daf492579352008b830b8d7bb1cac755573bdc0d7a7788dcd869dc4ecbd65d2bf62829dfdb804e9e6131b76c6744e6a944364908c4313956d05dd9ed')

build() {
  local cmake_options=(
    -B build
    -D CMAKE_BUILD_TYPE=None
    -D CMAKE_INSTALL_LIBDIR=lib
    -D CMAKE_INSTALL_PREFIX=/usr
    -D PERF_TEST=ON
    -D RTOSC_BUILD_SHARED_LIBS=ON
    -S $pkgbase-$pkgver
    -W no-dev
  )

  cmake "${cmake_options[@]}"
  cmake --build build --verbose
  cmake --build build --target rtosc-doc --verbose
}

check() {
  ctest --test-dir build --output-on-failure
}

package_rtosc() {
  depends=(
    gcc-libs
    glibc
  )
  optdepends=('rtosc-docs: for developer documentation')
  provides=(
    librtosc.so
    librtosc-cpp.so
  )

  DESTDIR="$pkgdir" cmake --install build
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgbase/"
}

package_rtosc-docs() {
  pkgdesc+=" - documentation"

  install -vDm 644 $pkgbase-$pkgver/{README,doc/Guide}.adoc -t "$pkgdir/usr/share/doc/$pkgbase/"
  install -vDm 644 build/html/search/* -t "$pkgdir/usr/share/doc/$pkgbase/html/search/"
  install -vDm 644 build/html/*.{css,html,js,png,svg} -t "$pkgdir/usr/share/doc/$pkgbase/html/"
  install -vDm 644 $pkgbase-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
